﻿<UserControl x:Class="GarageManagement.Pages.Customers"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:lex="http://wpflocalizeextension.codeplex.com"
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
             lex:ResxLocalizationProvider.DefaultAssembly="GarageManagement"
             lex:ResxLocalizationProvider.DefaultDictionary="Garages"
             xmlns:datagrid="Xceed.Wpf.DataGrid"
             mc:Ignorable="d" 
             d:DesignHeight="600" d:DesignWidth="800"
             DataContext="{Binding CustomerViewModel,Source={StaticResource Locator}}">
    <Grid Style="{StaticResource ContentRoot}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="250"/>
            <ColumnDefinition Width="6"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <ScrollViewer Margin="{StaticResource SplitLeft}">
            <StackPanel>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition Height="5"/>
                        <RowDefinition/>
                        <RowDefinition Height="5"/>
                        <RowDefinition/>
                        <RowDefinition Height="5"/>
                        <RowDefinition/>
                        <RowDefinition Height="5"/>
                        <RowDefinition/>
                        <RowDefinition Height="5"/>
                        <RowDefinition/>
                        <RowDefinition Height="5"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="5"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" Text="{lex:Loc Garage_Customer_Filter}" Style="{StaticResource Heading2}" />
                    <TextBlock Grid.Row="1" Text="{lex:Loc Garage_Customer_LisencePlate}"/>
                    <TextBox Grid.Row="3" Text="{Binding LisencePlate,Mode=TwoWay}"/>
                    <TextBlock Grid.Row="5" Text="{lex:Loc Garage_Customer_Code}"/>
                    <TextBox Grid.Row="7" Text="{Binding CustomerCode, Mode=TwoWay}"/>
                    <Button Grid.Row="9" Content="{lex:Loc Garage_Customer_FilterButton}" 
                            Command="{Binding SearchCommand}"
                            Width="100" HorizontalAlignment="Right"/>
                    <TextBlock Grid.Row="11" Text="{lex:Loc Garage_Customer_List}" Style="{StaticResource Heading2}" />
                    <ListView Grid.Row="13" ItemsSource="{Binding CustomerList, Mode=TwoWay}"
                              SelectionMode="Single"
                              SelectedItem="{Binding SelectedCustomer, Mode=TwoWay}">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <WrapPanel>
                                    <TextBlock Text="{Binding Code}" FontWeight="Bold" />
                                    <TextBlock Text=" - " />
                                    <TextBlock Text="{Binding ContactName}"/>
                                </WrapPanel>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                </Grid>
            </StackPanel>
        </ScrollViewer>
        <GridSplitter Grid.Column="1" />
        <ScrollViewer Grid.Column="2 " Margin="{StaticResource SplitRight}">
            <StackPanel>
                <TextBlock Text="{lex:Loc Garage_Customer_Detail}" Style="{StaticResource Heading2}" />
                <Grid Margin="20">
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="5"/>
                        <RowDefinition/>
                        <RowDefinition Height="5"/>
                        <RowDefinition/>
                        <RowDefinition Height="5"/>
                        <RowDefinition/>
                        <RowDefinition Height="5"/>
                        <RowDefinition/>
                        <RowDefinition Height="5"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="15"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>

                    <TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" Text="{lex:Loc Garage_Customer_Code}"/>
                    <TextBox Grid.Row="0" Grid.Column="2"  Text="{Binding SelectedCustomer.Code,Mode=TwoWay}" IsEnabled="{Binding IsEnabled}"/>
                    <TextBlock Grid.Row="0" Grid.Column="4" HorizontalAlignment="Right" Text="{lex:Loc Garage_Customer_ContactName}"/>
                    <TextBox Grid.Row="0" Grid.Column="6" Text="{Binding SelectedCustomer.ContactName,Mode=TwoWay}" IsEnabled="{Binding IsEnabled}"/>

                    <TextBlock Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right" Text="{lex:Loc Garage_Customer_Address}"/>
                    <TextBox Grid.Row="2" Grid.Column="2" Text="{Binding SelectedCustomer.Address,Mode=TwoWay}" IsEnabled="{Binding IsEnabled}"/>
                    <TextBlock Grid.Row="2" Grid.Column="4" HorizontalAlignment="Right" Text="{lex:Loc Garage_Customer_City}"/>
                    <TextBox Grid.Row="2" Grid.Column="6" Text="{Binding SelectedCustomer.City,Mode=TwoWay}" IsEnabled="{Binding IsEnabled}"/>

                    <TextBlock Grid.Row="4" Grid.Column="0" HorizontalAlignment="Right" Text="{lex:Loc Garage_Customer_HomePhone}"/>
                    <TextBox Grid.Row="4" Grid.Column="2" Text="{Binding SelectedCustomer.Telephone,Mode=TwoWay}" IsEnabled="{Binding IsEnabled}"/>
                    <TextBlock Grid.Row="4" Grid.Column="4" HorizontalAlignment="Right" Text="{lex:Loc Garage_Customer_WorkPhone}"/>
                    <TextBox Grid.Row="4" Grid.Column="6" Text="{Binding SelectedCustomer.Telephone,Mode=TwoWay}" IsEnabled="{Binding IsEnabled}"/>

                    <TextBlock Grid.Row="6" Grid.Column="0" HorizontalAlignment="Right" Text="{lex:Loc Garage_Customer_Mobile}"/>
                    <TextBox Grid.Row="6" Grid.Column="2" Text="{Binding SelectedCustomer.MobilePhone,Mode=TwoWay}" IsEnabled="{Binding IsEnabled}"/>
                    <TextBlock Grid.Row="6" Grid.Column="4" HorizontalAlignment="Right" Text="{lex:Loc Garage_Customer_Fax}"/>
                    <TextBox Grid.Row="6" Grid.Column="6" Text="{Binding SelectedCustomer.Fax,Mode=TwoWay}" IsEnabled="{Binding IsEnabled}"/>

                    <TextBlock Grid.Row="8" Grid.Column="0" HorizontalAlignment="Right" Text="{lex:Loc Garage_Customer_Email}"/>
                    <TextBox Grid.Row="8" Grid.Column="2" Text="{Binding SelectedCustomer.Email,Mode=TwoWay}" IsEnabled="{Binding IsEnabled}"/>
                    <TextBlock Grid.Row="8" Grid.Column="4" HorizontalAlignment="Right" Text="{lex:Loc Garage_Customer_Type}"/>
                    <ComboBox Grid.Row="8" Grid.Column="6" ItemsSource="{Binding CustomerTypes}" 
                              SelectedItem="{Binding SelectedCustomer.CustomerType}"
                              IsEnabled="{Binding IsEnabled}">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Name}"/>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>

                    <TextBlock Grid.Row="10" Grid.ColumnSpan="7" Text="{lex:Loc Garage_Customer_CarList}" Style="{StaticResource Heading2}" />
                    <Grid Grid.Column="10" Grid.RowSpan="10">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"/>
                            <RowDefinition Height="5"/>
                            <RowDefinition Height="30"/>
                            <RowDefinition Height="5"/>
                            <RowDefinition Height="30"/>
                        </Grid.RowDefinitions>
                        <Button Grid.Row="0" Content="{lex:Loc Garage_Customer_CreateNew}" Command="{Binding NewCustomerCommand}"/>
                        <Button Grid.Row="2" Content="{lex:Loc Garage_Customer_Edit}" Command="{Binding EditCustomerCommand}"/>
                        <Button Grid.Row="4" Content="{lex:Loc Garage_Customer_Delete}" Command="{Binding DeleteCustomerCommand}"/>
                    </Grid>
                </Grid>

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <xcdg:DataGridControl x:Name="VehicleGrid" ItemsSource="{Binding CustomerList}"
                                          AutoCreateColumns="False">
                        <xcdg:DataGridControl.View>
                            <xcdg:TableflowView FixedColumnCount="2"  />
                        </xcdg:DataGridControl.View>

                        <xcdg:DataGridControl.Columns>
                            <xcdg:Column FieldName="CustomerId"
                             Title="CustomerId"
                             Width="100"
                             IsMainColumn="True"
                                         ReadOnly="True">
                            </xcdg:Column>
                            <xcdg:Column FieldName="Code"
                             Title="Code"
                             Width="100"
                             IsMainColumn="True">
                            </xcdg:Column>
                            <xcdg:Column FieldName="ContactName"
                             Title="ContactName"
                             Width="200"
                             IsMainColumn="True">
                            </xcdg:Column>
                        </xcdg:DataGridControl.Columns>


                    </xcdg:DataGridControl>
                </Grid>

                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="180"/>
                    </Grid.ColumnDefinitions>
                    <Button Content="{lex:Loc Garage_Customer_SaveChanges}" 
                            Grid.Column="0" HorizontalAlignment="Right" 
                            Width="150"
                            Command="{Binding SaveCommand}"/>
                    <Button Content="{lex:Loc Garage_Customer_Cancel}" 
                            Grid.Column="1" HorizontalAlignment="Right" 
                            Width="150" Margin="0 0 20 0"
                            Command="{Binding CancelCommand}"/>
                </Grid>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</UserControl>
